
/* defines */
#define COM1_INT_ID 0x0c
#define ERR_SERIAL_PORT_NOT_OPEN (-201)
#define PIC_MASK 0x21
#define INTERRUPT_FLAG 0X20
#define COM1_BASE 0x3F8 /* com base address */
#define COM1_INT_EN COM1_BASE + 1 /* interrupt enable */
#define COM1_INT_ID_REG COM1_BASE + 2 /* interrupt ID register */
#define COM1_LC COM1_BASE + 3 /* line control */
#define COM1_MC COM1_BASE + 4 /* modem control */
#define COM1_MS COM1_BASE + 5 /* modem status */
#define COM1_BRD_LSB COM1_BASE
#define COM1_BRD_MSB COM1_BASE + 1

#define INVALID_EVEN_FLAG_POINTER 101
#define INVALID_BAND_RATE_DIVISOR 102
#define ERROR_PORT_ALREADY_OPEN   103
#define IDLE 0
#define ACTIVE 1
#define WRITE 2
#define READING 3

#define SERIAL_PORT_NOT_OPEN 401
#define INVALID_BUFFER_ADDRESS 402
#define INVALID_COUNT_ADDRESS_OR_COUNT_VALUE 403
#define DEVICE_BUSY 404


/* device control block */
typedef struct DCB{
  int open;
  int status;
  int *eventFlag;
  char* in_buff;
  int *in_count;
  int in_done;
  char* out_buff;
  int *out_count;
  int out_done;
  char ring_buffer[200];
  int ring_buffer_in;
  int ring_buffer_out;
  int ring_buffer_count;
} dcb;

/* function prototypes */
int com_open (int *eflag_p, int baud_rate);
int com_close (void);
int com_read (char *buf_p, int *count_p);
int com_write (char *buf_p, int *count_p);
void interrupt comHandler();
void comRead();
void comWrite();
iod* removeIOD(iocb *queue);
void addIOD(iod* newRequest, iocb *queue);
void initIO(int *terminal, int *comPort);
void ioComplete(iocb *queue);
void beginIO(iod *current);
